<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->

<link href="<%=basePath %>resources/css/bootstrap.min.css" rel="stylesheet" media="screen">
<script src="<%=basePath %>resources/jslib/jquery.js"></script>
<script src="<%=basePath %>resources/jslib/bootstrap.min.js"></script>
<script  type="text/javascript">

//登录
	function saveUserInfo() {
		$("#mes").show();
		$("#mes").html("&nbsp;&nbsp;正在登录中...");
		
		var password=$("#password").val();
		var comPassword=$("#comfigPassword").val();
		if(password.length<6){
			$("#mes").html("&nbsp;&nbsp;密码长度为6-16位");
			return ;
		}
		if(password.length>16&&password.length!=32){
			$("#mes").html("&nbsp;&nbsp;密码长度为6-16位");
			return ;
		}
		if(password!=comPassword){
			$("#mes").html("&nbsp;&nbsp;2此输入密码不一致...");
			return ;
		}
		var loginName=$("#loginName").val();
		if(loginName.length<0){
			$("#mes").html("&nbsp;&nbsp;登陆名不能为空");
			return ;
		}
		//登录处理
		var param={"id":$("#uid").val(),
				  "userName":$("#loginName").val(),
				  "userCode":$("#userName").val(),
				  "userTel":$("#phoneNumber").val(),
				  "password":$("#password").val(),
				  "roleID":$("#roleId").val()
				  };
		$.ajax({
			type: "post",
			contentType: "application/json;charset=utf-8",
			url : "<%=basePath %>user/updateUser.action",
			data :JSON.stringify(param) ,
			success : function(data){
                       if(data.code=="0000"){
                    	   alert("修改成功"); 
                       }else{
                          $("#mes").html(data.code+"##"+data.message);
                        }
                      
             },
			 dataType : "json"
		});
	}
</script>
</head>
<body>
<ol class="breadcrumb">
	<li><a href="#">登陆</a></li>
	<li><a href="#">首页</a></li>
	<li class="active">用户修改</li>
</ol>


<form class="form-horizontal" role="form">
 <input type="hidden" id="uid" name="uid" value="${userInfo.id }"/>
  <div class="form-group">
    <label class="col-sm-2 control-label">用户名：</label>
    <div class="col-sm-10">
      <input class="form-control" id="loginName" type="text" placeholder="请输入用户名用于登陆" value="${userInfo.userName }">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword" class="col-sm-2 control-label">联系人：</label>
    <div class="col-sm-10">
      <input class="form-control" id="userName" type="text" placeholder="该输入联系人"  value="${userInfo.userCode }" >
    </div>
  </div>

  <div class="form-group ">
    <label class="col-sm-2 control-label" for="inputSuccess">手机号码：</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="phoneNumber" placeholder="该输入手机号码"  value="${userInfo.userTel }" >
    </div>
  </div>
  <div class="form-group ">
    <label class="col-sm-2 control-label" for="inputSuccess">登陆密码：</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="password" placeholder="请输入密码，6位长度以上" value="${userInfo.password }">
    </div>
  </div>
  <div class="form-group">
    <label class="col-sm-2 control-label" for="inputSuccess">确认登陆密码</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="comfigPassword" placeholder="请再次输入手机号码，6位长度以上" value="${userInfo.password }">
    </div>
  </div>
   <div class="form-group">
   <label class="col-sm-2 control-label" for="inputSuccess">用户角色</label>
    <div class="col-sm-10">
      <select class="form-control"  id="roleId">
      <c:forEach items="${roles}" var="item"  varStatus="status">
          <option <c:if test="${item.id==userInfo.roleID}">selected='selected'</c:if> value="${item.id}">${item.roleName}</option>
        </c:forEach>
       </select>
    </div>
    
  </div>
   <div class="form-group">
       <label class="col-sm-2 control-label" for="inputSuccess"></label>
       <button type="button"  class="btn btn-success"  onclick="saveUserInfo()">确认保存</button>
      
    </div>
     <div class="form-group">
       <label class="col-sm-2 control-label" for="inputSuccess"></label>
       <p class="text-success" id="mes"></p>
    </div>
</form>

</body>
</html>